import { View } from './View';

/**
 * Frame class - Container for Views in the Mini-XAF application.
 * Each Frame displays a single View at a time.
 */
export class Frame {
  private _id: string;
  private _title: string;
  private _view: View | null = null;

  /**
   * Create a new Frame
   * @param id Frame identifier
   * @param title Frame title
   */
  constructor(id: string, title: string) {
    this._id = id;
    this._title = title;
  }

  /**
   * Get the frame ID
   */
  public get id(): string {
    return this._id;
  }

  /**
   * Get the frame title
   */
  public get title(): string {
    return this._title;
  }

  /**
   * Set the frame title
   */
  public set title(value: string) {
    this._title = value;
  }
  /**
   * Get the current view displayed in this frame
   */
  public get view(): View | null {
    return this._view;
  }

  /**
   * Set the view to display in this frame
   */
  public set view(value: View | null) {
    if (this._view !== value) {
      // Detach old view if exists
      if (this._view && this._view.frame === this) {
        this._view.setFrame(null);
      }
      
      this._view = value;
      
      // Attach new view if not null
      if (value) {
        value.setFrame(this);
      }
    }
  }

  /**
   * Set the view to display in this frame
   * @param view The view to display
   */
  public setView(view: View): void {
    this.view = view;
  }
}
